package com.xiaohui.user.designPattern.filter;

import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class ArticleFilterFactory {

    public static List<IArticleFilter> createArticleFilter(List<ArticleFilterEnum> articleFilterEnumList) {
        List<IArticleFilter> articleFilterList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(articleFilterEnumList)) {
            articleFilterList = articleFilterEnumList.stream()
                    .map(e -> createFilter(e))
                    .collect(Collectors.toList());
        }
        return articleFilterList;
    }

    public static IArticleFilter createFilter(ArticleFilterEnum articleFilterEnum) {
        IArticleFilter iArticleFilter = null;
        switch (articleFilterEnum) {
            case WORD_COUNT:
                iArticleFilter = new WordCountFilter();
                break;
            default:
                break;
        }
        return iArticleFilter;
    }
}
